<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.CkeditorConfigHelper"%>
<%@page import="java.util.TreeMap"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="helpers.DateHelper"%>
<%@page import="models.NewsModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="models.SiteConfigModel"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor" %>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
SiteConfigModel siteConfig = (SiteConfigModel) request.getAttribute("config");
String image = "";//UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
String name = (String) request.getAttribute("name");
ArrayList<NewsModel> lst_news = (ArrayList<NewsModel>) request.getAttribute("lst_news");
String form = (String) request.getAttribute("form");
String success = (String) request.getAttribute("success");
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<jsp:include page="/layouts/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>
<script type="text/javascript" src="/js/home.js"></script>
			<div class="block-content">
				<!-- STATIC PAGE -->
				<div class="static-block">
					<% if (success != null) { %>
					<div class="msg-s"><%=success %></div>
					<% } %>
					<div class="form-user">
						<h2>List news submited</h2>
						<form action="" method="post">
						<table class="news-table" cellpadding="0" cellspacing="0">
							<tbody>
								<% for (int i = 0; i < lst_news.size(); i++) { %>
								<tr class="news-item">
									<td class="first title">
										<a href="/goto?url=<%=URLEncoder.encode(lst_news.get(i).getUrl())%>"><%=lst_news.get(i).getTitle() %></a>
									</td>
									<td class="source"><a href="http://<%=UrlHelper.fomatDomains(lst_news.get(i).getUrl()) %>" target="_blank" class="link"><%=UrlHelper.fomatDomains(lst_news.get(i).getUrl()) %></a></td>
									<td class="date"> <%=DateHelper.getStringFromDate(lst_news.get(i).getCreated(), "yyyy-MM-dd HH:mm:ss")%></td>
									<td class="action">
										<ul>
											<li><a href="/edit-news/<%=URLEncoder.encode(lst_news.get(i).getId())%>">Edit</a></li>
											<li><a href="/delete-news/<%=URLEncoder.encode(lst_news.get(i).getId())%>">Delete</a></li>
										</ul>
									</td>
								</tr>
								<% } %>
							</tbody>
						</table>
						<!-- paginate -->
		                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
		                	<% if (prevPage) { %>
								<a class="previous paginate_button" id="dyntable_previous" href="<%=paginator.getPrev()%>">Previous</a>
							<% } else { %>
								<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Previous</span>
							<% } %>
							<% if (nextPage) { %>
								<a class="next paginate_button" id="dyntable_next"  href="<%=paginator.getNext()%>">Next</a>
							<% } else { %>
								<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Next</span>
							<% } %>
		                </div>
						</form>
					</div>
				</div>
				<!-- END STATIC PAGE -->
			</div>

<jsp:include page="/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>	